$(function () {
    // 预览框
    $('#window_view').window({
        modal: true,
        closed: true,
        width: 800,
        height: 600,
        title: '文件预览',
        onOpen: function () {
            $(this).window('center');
        }
    });

    $.post('sysUser/getName', {token: getTokenFromStorage()}, function (data) {
        if (data.success) {
            $('#user').html(data.data)
        }
    }, 'json')
})

function createIFrame(url) {
    return `<div style="width: 100%;height: 100%;">
                <iframe scrolling="auto" frameborder="0" src="${url + '?token=' + getTokenFromStorage()}" style="width:100%;height:100%;"></iframe>
            </div>`;
}

function loadViewPage(url) {
    $('#window_view').window({
        content: createIFrame(url)
    })
    $('#window_view').window('open');
}

jQuery.extend({
    enableFormElement: function (ele) {
        $("input[textboxname]", ele).each(function (i, n) {
            $(n).textbox('enable');
        });
        $(".easyui-filebox", ele).each(function (i, n) {
            $(n).filebox('enable');
        });
        $("input[switchbuttonname]", ele).each(function (i, n) {
            $(n).switchbutton('enable');
        });
        $(".easyui-linkbutton", ele).each(function (i, n) {
            if ($(n).linkbutton() != undefined) $(n).linkbutton('enable');
        });
        $(".easyui-checkbox", ele).each(function (i, n) {
            if ($(n).checkbox() != undefined) $(n).checkbox('enable');
        });
    },
    disableFormElement: function (ele) {
        $("input[textboxname]", ele).each(function (i, n) {
            $(n).textbox('disable');
        });
        $(".easyui-filebox", ele).each(function (i, n) {
            $(n).filebox('disable');
        });
        $("input[switchbuttonname]", ele).each(function (i, n) {
            $(n).switchbutton('disable');
        });
        $(".easyui-linkbutton", ele).each(function (i, n) {
            if ($(n).linkbutton() != undefined) $(n).linkbutton('disable');
        });
        $(".easyui-checkbox", ele).each(function (i, n) {
            if ($(n).checkbox() != undefined) $(n).checkbox('disable');
        });
    }
})

// 退出
function btn_logout() {
    $.messager.confirm('提示', '是否退出登录？', function (r) {
        if (r) {
            localStorage.clear();
            delCookie('token');
            window.location.href = "login";
        }
    })
}


function user_formatter(v, r, i) {
    if (!v) return '';
    let value_ = '';
    $.ajax({
        url: 'sysUser/queryByPk/' + v,
        async: false,
        dataType: 'json',
        type: 'GET',
        success: function (data) {
            if (data) {
                value_ = data['userName'];
            }
        }
    })
    return value_;
}